<template>
  <div class="company-style">
    <!-- 导航栏 start -->
    <van-nav-bar title="用户登录" right-text="" left-arrow fixed @click-left="onClickLeft"  />
    <!-- 导航栏 end -->

    <!-- 内容 -->
    <div class="user">
      <van-form @submit="onSubmit" class="form">
        <span class="title">欢迎HR回家</span>
        <van-field v-model="userName" size="large" name="用户名" placeholder="请输入用户名/绑定手机号" :rules="[{ required: true, message: '请填写用户名/绑定手机号' }]" style="font-size: 16px" />
        <van-field v-model="passWord" size="large" type="password" name="密码" placeholder="请输入密码" :rules="[{ required: true, message: '请填写密码' }]" style="font-size: 16px" />
        <div class="link" style="justify-content: flex-end" @click="$router.push({name:'company-forget'})">
          <span>忘记密码</span>
        </div>
				<van-field name="checkbox" class="read">
          <template #input>
            <van-checkbox v-model="checked" checked-color="#07f" icon-size="16px">
              <span>我同意</span>
            </van-checkbox>
						<span @click="onUserXY('xy')">《舟山人才网用户协议》</span>
            <span @click="onUserXY('zc')">《隐私政策》</span>
          </template>
        </van-field>
        <div class="btns">
          <van-button round block type="info" native-type="submit" :loading="loading">登录</van-button>
        </div>
        <div class="link" style="justify-content: center" @click="$router.push({name:'company-register'})">
          <span>新用户注册</span>
        </div>
				<div class="hotline" @click="toCall('0580-2186550')">
          <b>客服热线：0580-2186550</b>
        </div>
        <div class="identity">
          <span @click="onPerson">我要求职</span>
        </div>
      </van-form>
    </div>
  </div>
</template>

<script>
import { NavBar, Form, Field, Button, Toast,Checkbox, CheckboxGroup } from "vant";
import { addCompanyAutoLoginData, addCompanyLoginData, switchUserType } from '@/util/session';
import MyMixin from '@/mixin/MyMixin';
import { getPlatform, returnToPhoneWithData } from '@/util/phone';
export default {
  name: "LoginPage",
  components: {
    [NavBar.name]: NavBar,
    [Form.name]: Form,
    [Field.name]: Field,
    [Button.name]: Button,
		[Checkbox.name]: Checkbox,
    [CheckboxGroup.name]: CheckboxGroup,
  },
  // 定义属性
  data() {
    return {
      userName: '',
      passWord: '',
      loading: false,
			checked: false,
    };
  },
  mixins: [MyMixin],
  // 方法集合
  methods: {
    onSubmit() {
			if (!this.checked) { Toast('请同意用户协议'); return; }
      this.loading = true;
      this.$api.post('/CompanyAccount/Login', { userName: this.userName, passWord: this.passWord }).then(res => {
        this.loading = false;
        if (res.success) {
          this.loginSuccess(res.response);
        }
        else { Toast.fail(res.msg); }
      })
    },
    loginSuccess(data) {
			//save data to storage
      addCompanyLoginData(data.companyID, data.companyIDEncrpt, data.token);
      addCompanyAutoLoginData(this.userName, this.passWord)
			//jump
      this.$router.replace({ name: "company-main" });
      //jim web login
      // myJmessage.login(data.companyID, data.companyName);
      this.$chathub.bindConnID(data.companyID,data.token);
			//jim app login
			returnToPhoneWithData({ action: 'company_im_login', companyid: data.companyID })
    },
    onPerson() {
      this.switchUser('P');
    },
		toCall(phone){
			returnToPhoneWithData({action:'call',tel:phone})
		},
		//协议
    onUserXY(type) {
      this.$router.push({ name: "person-login-xy", query: { type } });
    },
  },
};
</script>

<style lang="less">
@import "vant/lib/index.less";
@import "@/assets/css/company.less";
@import "@/assets/css/company.css";
</style>